#include "Node.h"
#include <QPaintEvent>
#include <QPainter>

Node::Node(QWidget* parent) :
	MoveableItem(parent)
{
}

void Node::addJoin(BaseItem* join)
{
	joins.append(join);
}

void Node::paintEvent(QPaintEvent *event)
{
	Q_UNUSED(event)

	QPainter painter(this);
	painter.setBrush(QBrush(QColor(90,50,140)));
	painter.drawEllipse(0,0,_width-1,_height-1);
	painter.end();

	foreach(BaseItem* item, joins){
		item->update();
	}
}

void Node::mouseMoveEvent(QMouseEvent*event)
{
	if(!_moveable) return;
	if(!_pressed) return;
	int dx = event->globalPos().x() - _prevPos.x();
	int dy = event->globalPos().y() - _prevPos.y();

	_x0 += dx;
	_y0 += dy;

	setPosition(_x0,_y0);

	_prevPos = event->globalPos();

	repaint();
}
